import java.util.Scanner;
import java.util.*;
public class MC0409拯救圣莲池1 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        // code here
        int n = input.nextInt();
        int k = input.nextInt();
        int count = 0;//初始恢复之力为0
        // 存储灵力值
        PriorityQueue<Integer> pq = new PriorityQueue<>();//最小堆
        for(int i = 0;i < n;i++){
            pq.add(input.nextInt());
        }
        for (int i = 0; i < k; i++) {
            if (pq.isEmpty()){
                break;
            }
            //移除并返回此队列的队头元素
            int cur = pq.poll();
            count += cur;
            if (cur > 1){
                pq.add(cur - 1);
            }
        }
        System.out.println(count);
        input.close();
    }
}
